
package cfar.parallel.reduce;

import cfar.ff.fun.F2;
import cfar.ff.fun.Seq;
import cfar.ff.interfaces.Sequence;

/**
 *
 * @author badi
 */
public class Reduce<S,A> implements F2< F2<A,A,A>
                                      , Sequence<S,A>
                                      , A
                                      >
{

    public A f( F2<A, A, A> f
              , Sequence<S, A> seq
              )
    {
        Sequence<S,Integer> rs = (Sequence<S, Integer>) seq.<Integer>empty();
        for(int i = 0; i < seq.length(); i++)
            rs = rs.cons(1);
        return Seq.parRReduce(rs, Seq.<S,A>head(), f, seq);
    }

}
